import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

class MessagePage extends StatefulWidget {
  @override
  MessagePageState createState() => new MessagePageState();
}

class MessagePageState extends State<MessagePage> {

  final _suggestions = <WordPair>[];
  final _biggerFont = TextStyle(fontSize: 18.0);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('消息'),
      ),
      body: __buildSuggestions(),
    );
  }
  
  Widget __buildSuggestions(){
    return ListView.builder(itemBuilder:(context, i) {
      if(i.isOdd) return Divider();   // 添加分割线
      final index = i ~/ 2; // 除并取整  5 ～/ 2 = 2

      if(i >= _suggestions.length) {
          _suggestions.addAll(generateWordPairs().take(10));   // 随机生成10个单词
      }

      return __buildRow(_suggestions[index]);
    });
  }

  Widget __buildRow(WordPair pair){
    return ListTile(
      title: Text(
          pair.asPascalCase,
          style: _biggerFont,
      ),
    );
  }
}